package com.example.hotel_lxy.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.example.hotel_lxy.R;

import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;


/**
* 分享
* create by Sincerly on 9999/9/9 0009
**/
public class ImageDialog extends Dialog {
    private Context mContext;
    private OnDialogClickListener listener;
    private static String imgs;
    public ImageDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;

        init();
    }

    private View init() {
        View view = View.inflate(mContext, R.layout.dialog_img, null);
        PhotoView weixinhy=view.findViewById(R.id.img);
        Glide.with(getContext()).load(imgs).into(weixinhy);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        weixinhy.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float x, float y) {
                dismiss();
            }

            @Override
            public void onOutsidePhotoTap() {

            }
        });

//        weixinhy.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                dismiss();
//            }
//        });
        return view;
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    protected void onStop() {
        super.onStop();

    }



    public OnDialogClickListener getListener() {
        return listener;
    }

    public void setListener(OnDialogClickListener listener) {
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(true);
        setContentView(init());
    }

    public void showDialog() {
        if (!isShowing()) {
            show();
            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.height = DisplayUtils.getDisplayWidth(mContext) * 5 / 5;
//            lp.width = DisplayUtils.getDisplayWidth(mContext) * 10 / 10;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            getWindow().setAttributes(lp);
            getWindow().setGravity(Gravity.BOTTOM);
        }
    }

    public static ImageDialog show(Context context, OnDialogClickListener listener,String img) {
        ImageDialog dialog = new ImageDialog(context, R.style.BottomDialogStyle);
        dialog.setListener(listener);
        imgs=img;
        dialog.showDialog();
        return dialog;
    }

    public interface OnDialogClickListener {
        void sure();
    }
}